home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / commsos.c < prev    next >
C/C++ Source or Header  |  1993-11-21  |  44KB  |  1,479 lines

  1. /***********************************************************************/
  2. /* COMMSOS.C - sos commands.                                           */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1993 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\commsos.c 1.4 1993/09/01 16:25:56 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*man-start*********************************************************************
  53.  
  54.  
  55.  
  56. ========================================================================
  57. SOS COMMAND REFERENCE
  58. ========================================================================
  59. **man-end**********************************************************************/
  60.  
  61. /*-------------------------- external data ----------------------------*/
  62. extern LINE *first_command,*current_command,*last_command;
  63. extern LINE *next_line,*curr_line;
  64. extern VIEW_DETAILS *vd_current,*vd_first;
  65. extern char current_screen;
  66. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  67. extern char current_file;         /* pointer to current file */
  68. extern WINDOW *foot,*error_window;
  69. extern bool error_on_screen;
  70. extern char *rec;
  71. extern unsigned short rec_len;
  72. extern char *cmd_rec;
  73. extern unsigned short cmd_rec_len;
  74. extern char *pre_rec;
  75. extern unsigned short pre_rec_len;
  76. extern char mode_insert;        /* defines insert mode toggle */
  77. extern char in_profile;    /* indicates if processing profile */
  78. extern unsigned short file_start;
  79.  
  80. extern char *temp_cmd;
  81. extern char dir_filename[10];
  82. extern char dir_pathname[MAX_FILE_NAME+1];
  83. extern char sp_path[MAX_FILE_NAME+1] ;
  84. extern char sp_fname[MAX_FILE_NAME+1] ;
  85. extern char dir_path[MAX_FILE_NAME+1] ;    /* for dir and ls commands */
  86. extern bool prefix_changed;
  87. /*man-start*********************************************************************
  88. COMMAND
  89.      SOS ADDline - add blank line after focus line
  90.      SOS LINEAdd - add blank line after focus line
  91.  
  92. SYNTAX
  93.      ** effective only if bound to a key **
  94.  
  95. DESCRIPTION
  96.      The SOS ADDLINE command inserts a blank line in the file following
  97.      the focus line. The cursor is placed in the column under the first
  98.      non-blank in the focus line.
  99.  
  100. COMPATIBILITY
  101.      XEDIT: Compatible.
  102.      KEDIT: Compatible.
  103.  
  104. SEE ALSO
  105.      SOS DELLINE
  106.  
  107. STATUS
  108.      Complete
  109. **man-end**********************************************************************/
  110. #ifdef PROTO
  111. int Sos_addline(char *params)
  112. #else
  113. int Sos_addline(params)
  114. char *params;
  115. #endif
  116. /***********************************************************************/
  117. {
  118. /*--------------------------- local data ------------------------------*/
  119.  short rc;
  120. /*--------------------------- processing ------------------------------*/
  121. #ifdef TRACE
  122.  trace_function("commsos.c: Sos_addline");
  123. #endif
  124.  rc = Add("1");
  125. #ifdef TRACE
  126.  trace_return();
  127. #endif
  128.  return(rc);
  129. }
  130. /*man-start*********************************************************************
  131. COMMAND
  132.      SOS CURSORAdj - move first non-blank character to cursor
  133.  
  134. SYNTAX
  135.      ** effective only if bound to a key **
  136.  
  137. DESCRIPTION
  138.      The SOS CURSORADJ command moves text in the focus line so that
  139.      the first non-blank character appears under the cursor position.
  140.  
  141. COMPATIBILITY
  142.      XEDIT: N/A
  143.      KEDIT: Compatible.
  144.  
  145. STATUS
  146.      Complete
  147. **man-end**********************************************************************/
  148. #ifdef PROTO
  149. int Sos_cursoradj(char *params)
  150. #else
  151. int Sos_cursoradj(params)
  152. char *params;
  153. #endif
  154. /***********************************************************************/
  155. {
  156. /*--------------------------- local data ------------------------------*/
  157.  short num_cols,first_non_blank_col,col,rc;
  158.  unsigned short x,y;
  159. /*--------------------------- processing ------------------------------*/
  160. #ifdef TRACE
  161.  trace_function("commsos.c: Sos_cursoradj");
  162. #endif
  163.  getyx(CURRENT_WINDOW,y,x);
  164.  switch (CURRENT_VIEW->current_window)
  165.    {
  166.     case WINDOW_MAIN:
  167.          if (FOCUS_TOF || FOCUS_BOF)
  168.            {
  169.             display_error(38,(char *)"");
  170. #ifdef TRACE
  171.             trace_return();
  172. #endif
  173.             return(RC_INVALID_ENVIRON);
  174.            }
  175.          col = x + CURRENT_VIEW->verify_col - 1;
  176.          first_non_blank_col = strzne(rec,' ');
  177.          if (first_non_blank_col == (-1))
  178.             first_non_blank_col = 0;
  179.          num_cols = first_non_blank_col - col;
  180.          if (num_cols < 0)
  181.             rc = execute_shift_command(FALSE,-num_cols,CURRENT_VIEW->focus_line,1);
  182.          else
  183.             if (num_cols > 0)
  184.                rc = execute_shift_command(TRUE,num_cols,CURRENT_VIEW->focus_line,1);
  185.          break;
  186.     default:
  187.          break;
  188.    }
  189. #ifdef TRACE
  190.  trace_return();
  191. #endif
  192.  return(rc);
  193. }
  194. /*man-start*********************************************************************
  195. COMMAND
  196.      SOS DELBAck - delete the character to the left of the cursor
  197.  
  198. SYNTAX
  199.      ** effective only if bound to a key **
  200.  
  201. DESCRIPTION
  202.      The SOS DELBACK command moves the cursor one character to the left
  203.      and deletes the character now under the cursor.
  204.  
  205. COMPATIBILITY
  206.      XEDIT: N/A
  207.      KEDIT: Compatible.
  208.  
  209. SEE ALSO
  210.      SOS DELCHAR
  211.  
  212. STATUS
  213.      Complete
  214. **man-end**********************************************************************/
  215. #ifdef PROTO
  216. int Sos_delback(char *params)
  217. #else
  218. int Sos_delback(params)
  219. char *params;
  220. #endif
  221. /***********************************************************************/
  222. {
  223. /*------------------------- external data -----------------------------*/
  224.  extern bool extended_display_mode;
  225.  extern bool CMDARROWSTABLRx;
  226. /*--------------------------- local data ------------------------------*/
  227.  unsigned short x,y;
  228.  bool save_CMDARROWSTABLRx = CMDARROWSTABLRx;
  229. /*--------------------------- processing ------------------------------*/
  230. #ifdef TRACE
  231.  trace_function("commsos.c: Sos_delback");
  232. #endif
  233.  getyx(CURRENT_WINDOW,y,x);
  234.  switch (CURRENT_VIEW->current_window)
  235.    {
  236.     case WINDOW_MAIN:
  237.          if (FOCUS_TOF || FOCUS_BOF)
  238.            {
  239.             display_error(38,(char *)"");
  240. #ifdef TRACE
  241.             trace_return();
  242. #endif
  243.             return(RC_INVALID_ENVIRON);
  244.            }
  245.          break;
  246.     case WINDOW_COMMAND:
  247.          if (x == 0)
  248.            {
  249. #ifdef TRACE
  250.             trace_return();
  251. #endif
  252.             return(RC_OK);
  253.            }
  254.          mvwdelch(CURRENT_WINDOW,y,x-1);
  255.          if (x <= cmd_rec_len)
  256.            {
  257.             cmd_rec = (char *)memdelchr((char *)cmd_rec,
  258.                                                x-1,cmd_rec_len,1);
  259.             cmd_rec_len--;
  260.            }
  261. #ifdef TRACE
  262.          trace_return();
  263. #endif
  264.          return(RC_OK);
  265.          break;
  266.     case WINDOW_PREFIX:
  267.          if (x == 0)
  268.            {
  269. #ifdef TRACE
  270.             trace_return();
  271. #endif
  272.             return(RC_OK);
  273.